﻿using iMES.Basedata.IRepository;
using iMES.Basedata.IServices;
using iMES.Custom.IRepositories;
using iMES.Custom.IServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;

namespace iMES.WebApi.Controllers
{
    public partial class Basicdata_ProcessrouteController
    {
        private readonly IBasicdata_ProcessrouteService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IBasicdata_ProcessrouteListRepository _processLineListRepository;



        [ActivatorUtilitiesConstructor]
        public Basicdata_ProcessrouteController(
            IBasicdata_ProcessrouteService service,
            IHttpContextAccessor httpContextAccessor,
            IBasicdata_ProcessrouteListRepository processLineListRepository
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
            _processLineListRepository = processLineListRepository;
        }
        /// <summary>
        /// 获取工序数据采集信息列表
        /// </summary>
        /// <param name="Process_Id">工序</param>
        /// <returns></returns>
        [Route("getDetailRows"), HttpGet]
        public async Task<IActionResult> GetDetailRows(int ProcessLine_Id)
         {
            var rows = await _processLineListRepository.FindAsIQueryable(x => x.ProcessLine_Id == ProcessLine_Id)
         .ToListAsync();
            // 空值处理，防止Data is Null异常
            foreach (var row in rows)
            {
                row.ProcessLineType = row.ProcessLineType ?? string.Empty;
                row.Creator = row.Creator ?? string.Empty;
                row.Modifier = row.Modifier ?? string.Empty;
                // 其他string类型字段也可类似处理
                // 数值类型如decimal?、int?等可根据需要设为0或null
            }
            return JsonNormal(rows);
        }
    }
}
